import { Configuration, App } from '@midwayjs/core';
import * as koa from '@midwayjs/koa';
import * as validate from '@midwayjs/validate';
import * as info from '@midwayjs/info';
// import { DefaultErrorFilter } from './filter/default.filter.js';
// import { NotFoundFilter } from './filter/notfound.filter.js';
import { ReportMiddleware } from './middleware/report.middleware.js';
import DefaultConfig from './config/config.default.js';
import UnittestConfig from './config/config.unittest.js';
import { initdb_1, getdb } from "./config/initdb.js";
import { Application } from "./interface.js";
import { init_systemdb } from "./config/initdb.js";
import { DefaultErrorFilter } from "./filter/default.filter.js";
import { NotFoundFilter } from "./filter/notfound.filter.js";
import * as fsplus from 'fs-extra'
import * as axios from '@midwayjs/axios';
import * as swagger from '@midwayjs/swagger';
import * as upload from '@midwayjs/upload';
import * as orm from '@midwayjs/typeorm';





@Configuration({
  imports: [
    upload,
    {
      component: swagger,
      enabledEnvironment: ["local"]
    },
    axios,
    koa,
    validate,
    {
      component: info,
      enabledEnvironment: ["local"]
    },
    orm,
  ],
  importConfigs: [
    {
      default: DefaultConfig,
      unittest: UnittestConfig,
    },
  ],
})
export class MainConfiguration {
  @App('koa')
  app: Application;

  async onReady() {
    // add middleware
    this.app.useMiddleware([ReportMiddleware]);
    // add filter
    this.app.useFilter([NotFoundFilter, DefaultErrorFilter]);
    this.app.sqiltedb = getdb({
      type: 'sqlite',
      host: 'mydatabase.db',
      id: 0,
      port: 0,
      user: '',
      password: '',
      database: '',
    })

    this.app.systemdb = init_systemdb()
    this.app.erpdb = getdb({
      "id": 1,
      "host": "192.168.11.204",
      "port": 13306,
      "user": "root",
      "password": "15s6f9E3613f9k",
      "database": "szq_erp",
      type: '',
    })
    this.app.mesdb = await getdb({
      "id": 1,
      "host": "192.168.11.204",
      "port": 13306,
      "user": "root",
      "password": "15s6f9E3613f9k",
      "database": "szq_mes",
      type: '',
    })




  }
}
